-
-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add if_not_exists to create_view and if_exists to drop_view #382
base: main
Are you sure you want to change the base?
Add if_not_exists to create_view and if_exists to drop_view #382
Conversation
380eccf
to
e145024
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some files could not be reviewed due to errors:
Warning: unrecognized cop Layout/ParameterAlignment found in .rubocop.yml
Warning: unrecognized cop Layout/ParameterAlignment found in .rubocop.yml Warning: unrecognized cop Layout/AssignmentIndentation found in .rubocop.yml Warning: unrecognized cop Lint/DuplicateHashKey found in .rubocop.yml Error: Unknown Ruby version 2.7 found in `TargetRubyVersion` parameter (in .rubocop.yml). Supported versions: 2.1, 2.2, 2.3, 2.4, 2.5
210d552
to
f4da7c1
Compare
@derekprior Hi! Hope you are well. |
6b76770
to
5863bee
Compare
Can you say more about this?
Conceptually, one of the ideas of Scenic is that careful management of your schema using Scenic means you have certainty around your database state. |
@derekprior Sure! class CreateSomeView < ActiveRecord::Migration[7.0]
disable_ddl_transaction!
def up
create_view :mv_some_name, materialized: true
safety_assured do
add_index :mv_some_name, :receipt_uuid, unique: true, algorithm: :concurrently
add_index :mv_some_name, :invoice_number, algorithm: :concurrently
end
end
def down
drop_view :mv_some_name, materialized: true
end
end As it's recommended to update indexes concurrently out of a transaction, those operations may accidentally fail. It happens very rarely, but we faced it several times. As a result, migration will stuck and it will require manual resolution. The change that I made doesn't bring some level of uncertainty, I think. As by default, we do everything like we did before, but if we really need to make it a bit flexible, we now can do that. Please let me know if it makes sense. |
5863bee
to
b401623
Compare
@derekprior Hey! Hope you are doing well. Have you had a chance to take a look? |
Provide an ability to pass
if_not_exists
param for view creation. It's handy to have it when you disable_ddl_transaction in Rails migration and add indexes concurrently.And similar functionality with
if_exists
param to drop a view.For instance we have a migration like that:
As it's recommended to update indexes concurrently out of a transaction, those operations may accidentally fail. It happens very rarely, but we faced it several times. As a result, migration will stuck and it will require manual resolution.
The change that I made doesn't bring some level of uncertainty, I think. As by default, we do everything like we did before, but if we really need to make it a bit flexible, we now can do that.
Please let me know if it makes sense.
Thank you in advance!